<?php
/**
 * Модель product_to_order
 * 
 * Класс модели
 * @author Anton Zavidov
 * @package myLiveShop
 */

/**
 * Модель product_to_order
 *
 */
class ModelProduct_to_order extends Model {
	
	const TABLE				    = 'product_to_order';
	const F_PRODUCT_TO_ORDER_ID = 'product_to_order_id';
	const F_PRODUCT_ID         	= 'product_id';
	const F_ORDER_ID  		    = 'order_id';
	const F_PRODUCT_COUNT   	= 'product_count';
	const F_PARAMS         		= 'params';
			
	public function __construct($className=null){
		parent::__construct(__CLASS__);
		$this->name='product_to_order';
		$this->id_field=array(self::F_PRODUCT_TO_ORDER_ID);
		$this->fields=array(
		self::TABLE.DOT.self::F_PRODUCT_TO_ORDER_ID=> new Field($this,self::F_PRODUCT_TO_ORDER_ID,self::TABLE,array(
				'important'=>true,
				'lenght'=>9,
				'auto'=>true)),
		self::TABLE.DOT.self::F_PRODUCT_ID=> new Field($this,self::F_PRODUCT_ID,self::TABLE,array(
				'important'=>true,
				'lenght'=>11,
				'join_table'=>'product')),
		self::TABLE.DOT.self::F_ORDER_ID=> new Field($this,self::F_ORDER_ID,self::TABLE,array(
				'important'=>true,
				'lenght'=>11,
				'join_table'=>'order')),
		self::TABLE.DOT.self::F_PRODUCT_COUNT=> new Field($this,self::F_PRODUCT_COUNT,self::TABLE,array(
				'lenght'=>6)),
		self::TABLE.DOT.self::F_PARAMS=> new Field($this,self::F_PARAMS,self::TABLE,array(
				'type'=>Field::TYPE_TEXT))		);
	}
	/**
	 * сохраняем сразу много продуктов для одного заказа
	 *
	 * @param array $data многомерный массив с записями
	 * @return bool
	 */
	public function saveList($data){
		return $this->db->insert(self::TABLE, $data);
	}
}
